/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.documentar.controller;

import br.com.documentar.interfacee.InterfaceController;
import br.com.documentar.model.TabelaModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Santos
 */
public class TabelaController implements InterfaceController<TabelaModel> {

    br.com.documentar.DAO.TabelaDAO dao = new br.com.documentar.DAO.TabelaDAO();

    @Override
    public TabelaModel getModel() {
        return new br.com.documentar.model.TabelaModel();
    }

    @Override
    public DefaultTableModel insertTableModel(TabelaModel model) {
        model.getModelTable().setNumRows(0);
        for (br.com.documentar.model.TabelaModel p : dao.getDados(model)) {
            model.getModelTable().addRow(new Object[]{
                p.getCodigo(),
                p.getProduto().getCodigo() + " - " + p.getProduto().getNome(),
                p.getNome(), 
                p.getNomeAmigavel(), 
                p.getComentario(), 
                p.getTableSpace(),
                p.getTemporaria(), 
                p.getDono(), 
                p.getAtivo(), 
                p.getTipoBanco(),
                p.getNomeBanco(),
                p.getSql()});
        }
        return model.getModelTable();
    }

    @Override
    public DefaultTableModel getDadosTableModel(TabelaModel model) {
        return insertTableModel(model);
    }

    @Override
    public boolean setDados(TabelaModel model) {
        return dao.setDados(model);
    }

    @Override
    public DefaultComboBoxModel getDadosComboBoxModel(TabelaModel model) {
        return insertComboBoxModel(model);
    }

    @Override
    public DefaultComboBoxModel insertComboBoxModel(TabelaModel model) {
        for (br.com.documentar.model.TabelaModel p : dao.getDados(model)) {
            model.getModelComboBox().addElement(p.getCodigo() + " - " + p.getNome());
        }
        return model.getModelComboBox();
    }
}
